package com.baidu.mapapi;

import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.ZoomControls;
import java.io.InputStream;
import java.util.List;

public class MapView extends ViewGroup
{
  d a;
  a b;
  private GeoPoint c = new GeoPoint(0, 0);
  private int d = 12;
  private int e = 0;
  private int f = 0;
  private boolean g = false;
  private Message h = null;
  private Runnable i = null;
  private MapActivity j = null;
  private MapController k;
  private ZoomControls l;
  private ImageView m;

  public MapView(Context paramContext)
  {
    super(paramContext);
    this.a = new d(this);
    this.l = new ZoomControls(getContext());
    this.m = new ImageView(getContext());
    this.b = new a(getContext(), this);
    a(paramContext);
  }

  public MapView(Context paramContext, AttributeSet paramAttributeSet)
  {
    super(paramContext, paramAttributeSet);
    this.a = new d(this);
    this.l = new ZoomControls(getContext());
    this.m = new ImageView(getContext());
    this.b = new a(getContext(), this);
    a(paramContext);
  }

  public MapView(Context paramContext, AttributeSet paramAttributeSet, int paramInt)
  {
    super(paramContext, paramAttributeSet, paramInt);
    this.a = new d(this);
    this.l = new ZoomControls(getContext());
    this.m = new ImageView(getContext());
    this.b = new a(getContext(), this);
    a(paramContext);
  }

  private void a(View paramView, ViewGroup.LayoutParams paramLayoutParams)
  {
    LayoutParams localLayoutParams;
    int i3;
    int i4;
    int i5;
    int i6;
    paramView.measure(this.e, this.f);
    int i1 = paramLayoutParams.width;
    int i2 = paramLayoutParams.height;
    if (i1 == -1)
    {
      i1 = this.e;
      if (i2 != -1)
        break label252;
      i2 = this.f;
      if (!(checkLayoutParams(paramLayoutParams)))
        break label348;
      localLayoutParams = (LayoutParams)paramLayoutParams;
      i3 = localLayoutParams.x;
      i4 = localLayoutParams.y;
      if ((localLayoutParams.mode != 0) || (localLayoutParams.point == null))
        break label360;
      Point localPoint = getProjection().toPixels(localLayoutParams.point, null);
      i5 = localPoint.x + localLayoutParams.x;
      i6 = localPoint.y + localLayoutParams.y;
    }
    while (true)
    {
      switch (localLayoutParams.alignment)
      {
      case 3:
      case 48:
      case 51:
      default:
        paramView.layout(i5, i6, i1 + i5, i2 + i6);
      case 80:
      case 5:
      case 81:
      case 17:
      case 1:
      case 16:
      }
      while (true)
      {
        while (true)
        {
          while (true)
          {
            while (true)
            {
              while (true)
              {
                while (true)
                {
                  while (true)
                  {
                    while (true)
                    {
                      label252: 
                      do
                        while (true)
                        {
                          do
                            return;
                          while (i1 != -2);
                          i1 = paramView.getMeasuredWidth();
                        }
                      while (i2 != -2);
                      i2 = paramView.getMeasuredHeight();
                    }
                    i6 -= i2;
                  }
                  i5 -= i1;
                }
                i5 -= i1 / 2;
                i6 -= i2;
              }
              i5 -= i1 / 2;
              i6 -= i2 / 2;
            }
            i5 -= i1 / 2;
          }
          i6 -= i2 / 2;
        }
        label348: paramView.layout(0, 0, i1, i2);
      }
      label360: i5 = i3;
      i6 = i4;
    }
  }

  private boolean a(Context paramContext)
  {
    MapActivity localMapActivity = (MapActivity)paramContext;
    this.e = Mj.g;
    this.f = Mj.h;
    this.j = localMapActivity;
    return localMapActivity.a(this);
  }

  private void b(int paramInt)
  {
    this.d = paramInt;
    b();
  }

  void a(int paramInt1, int paramInt2)
  {
    Mj.MapProc(4354, paramInt1, paramInt2);
  }

  void a(GeoPoint paramGeoPoint)
  {
    this.c = paramGeoPoint;
    Mj.MapProc(4102, paramGeoPoint.getLongitudeE6(), paramGeoPoint.getLatitudeE6());
  }

  void a(GeoPoint paramGeoPoint, Message paramMessage, Runnable paramRunnable)
  {
    this.c = paramGeoPoint;
    Mj.MapProc(4353, paramGeoPoint.getLongitudeE6(), paramGeoPoint.getLatitudeE6());
    this.h = paramMessage;
    this.i = paramRunnable;
  }

  void a(boolean paramBoolean)
  {
    if (paramBoolean)
      Mj.MapProc(4355, 1, 0);
    while (true)
    {
      return;
      Mj.MapProc(4355, 0, 0);
    }
  }

  boolean a()
  {
    this.k = new MapController(this);
    Mj.e = this.b;
    addView(this.b);
    this.l.setOnZoomOutClickListener(new View.OnClickListener(this)
    {
      public void onClick()
      {
        this.a.e();
      }
    });
    this.l.setOnZoomInClickListener(new View.OnClickListener(this)
    {
      public void onClick()
      {
        this.a.d();
      }
    });
    this.l.setFocusable(true);
    this.l.setVisibility(0);
    this.l.measure(0, 0);
    try
    {
      InputStream localInputStream = this.j.getAssets().open("baidumap_logo.png");
      Bitmap localBitmap = BitmapFactory.decodeStream(localInputStream);
      localInputStream.close();
      if (localBitmap != null)
      {
        this.m.setImageBitmap(localBitmap);
        this.m.setVisibility(0);
        this.m.measure(0, 0);
        this.m.setScaleType(ImageView.ScaleType.FIT_CENTER);
        addView(this.m);
      }
      this.b.setFocusable(true);
      this.b.setFocusableInTouchMode(true);
      return true;
    }
    catch (Exception localException)
    {
      Log.d("MapView()", "initMapView() error!");
      Log.d("MapView()", localException.getMessage());
    }
  }

  boolean a(int paramInt)
  {
    int i1 = 3;
    if (paramInt < i1);
    while (true)
    {
      while (true)
      {
        if (this.d != i1)
        {
          this.d = i1;
          Mj.MapProc(4098, i1, 1);
          b();
        }
        return true;
        if (paramInt <= 18)
          break;
        i2 = 18;
      }
      int i2 = paramInt;
    }
  }

  boolean a(int paramInt1, int paramInt2, int paramInt3)
  {
    int i1;
    switch (paramInt1)
    {
    default:
      i1 = 0;
      return i1;
    case 9:
      if (this.b == null)
        break label61;
      this.b.a = true;
      invalidate();
    case 505:
    case 8020:
    }
    while (true)
    {
      label61: label110: 
      do
        while (true)
        {
          do
          {
            while (true)
            {
              while (true)
                i1 = 1;
              b(paramInt2);
            }
            if (this.h == null)
              break label110;
          }
          while (this.h.getTarget() == null);
          this.h.getTarget().sendMessage(this.h);
        }
      while (this.i == null);
      this.i.run();
    }
  }

  void b()
  {
    boolean bool1;
    ZoomControls localZoomControls2;
    boolean bool2;
    ZoomControls localZoomControls1 = this.l;
    if (this.d > 3)
    {
      bool1 = true;
      localZoomControls1.setIsZoomOutEnabled(bool1);
      localZoomControls2 = this.l;
      if (this.d >= getMaxZoomLevel())
        break label51;
      bool2 = true;
    }
    while (true)
    {
      while (true)
      {
        localZoomControls2.setIsZoomInEnabled(bool2);
        return;
        bool1 = false;
      }
      label51: bool2 = false;
    }
  }

  void b(int paramInt1, int paramInt2)
  {
    Mj.MapProc(4103, paramInt1 + this.e / 2, paramInt2 + this.f / 2);
  }

  void c()
  {
    int i1 = getChildCount();
    int i2 = 0;
    if (i2 < i1)
    {
      View localView = super.getChildAt(i2);
      if ((localView == this.m) || (localView == this.l) || (localView == this.b));
      while (true)
      {
        ViewGroup.LayoutParams localLayoutParams;
        do
        {
          while (true)
            ++i2;
          localLayoutParams = localView.getLayoutParams();
        }
        while ((!(localLayoutParams instanceof LayoutParams)) || (((LayoutParams)localLayoutParams).mode != 0));
        a(localView, localLayoutParams);
      }
    }
  }

  public boolean canCoverCenter()
  {
    int i1;
    Bundle localBundle = new Bundle();
    localBundle.putInt("act", 15010001);
    Mj.sendBundle(localBundle);
    if (localBundle.getInt("r") != 0)
      i1 = 1;
    while (true)
    {
      return i1;
      i1 = 0;
    }
  }

  protected boolean checkLayoutParams(ViewGroup.LayoutParams paramLayoutParams)
  {
    return paramLayoutParams instanceof LayoutParams;
  }

  public void computeScroll()
  {
    super.computeScroll();
  }

  boolean d()
  {
    int i1;
    if (this.d >= 18)
      i1 = 0;
    while (true)
    {
      return i1;
      this.b.a(1, this.e / 2, this.f / 2);
      i1 = 1;
    }
  }

  public void displayZoomControls(boolean paramBoolean)
  {
    removeView(this.l);
    addView(this.l);
    if (paramBoolean)
      requestChildFocus(this.l, this.l);
  }

  boolean e()
  {
    int i1;
    if (this.d <= 3)
      i1 = 0;
    while (true)
    {
      return i1;
      this.b.a(-1, this.e / 2, this.f / 2);
      i1 = 1;
    }
  }

  double f()
  {
    return Math.pow(2.0D, 18 - this.d);
  }

  protected ViewGroup.LayoutParams generateDefaultLayoutParams()
  {
    return super.generateDefaultLayoutParams();
  }

  public ViewGroup.LayoutParams generateLayoutParams(AttributeSet paramAttributeSet)
  {
    return new LayoutParams(this.j, paramAttributeSet);
  }

  protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams paramLayoutParams)
  {
    return new LayoutParams(paramLayoutParams);
  }

  public MapController getController()
  {
    return this.k;
  }

  public int getLatitudeSpan()
  {
    d locald = (d)getProjection();
    GeoPoint localGeoPoint1 = locald.fromPixels(0, 0);
    GeoPoint localGeoPoint2 = locald.fromPixels(this.e - 1, this.f - 1);
    return Math.abs(localGeoPoint1.getLatitudeE6() - localGeoPoint2.getLatitudeE6());
  }

  public int getLongitudeSpan()
  {
    d locald = (d)getProjection();
    GeoPoint localGeoPoint = locald.fromPixels(0, 0);
    return Math.abs(locald.fromPixels(this.e - 1, this.f - 1).getLongitudeE6() - localGeoPoint.getLongitudeE6());
  }

  public GeoPoint getMapCenter()
  {
    GeoPoint localGeoPoint;
    Bundle localBundle = Mj.GetMapStatus();
    if (localBundle != null)
    {
      int i1 = localBundle.getInt("x");
      localGeoPoint = new GeoPoint(localBundle.getInt("y"), i1);
    }
    while (true)
    {
      return localGeoPoint;
      localGeoPoint = this.c;
    }
  }

  public int getMaxZoomLevel()
  {
    return 18;
  }

  public final List<Overlay> getOverlays()
  {
    return this.b.a();
  }

  public Projection getProjection()
  {
    return this.a;
  }

  @Deprecated
  public View getZoomControls()
  {
    return this.l;
  }

  public int getZoomLevel()
  {
    return this.d;
  }

  public boolean isSatellite()
  {
    return false;
  }

  public boolean isStreetView()
  {
    return false;
  }

  public boolean isTraffic()
  {
    return this.g;
  }

  protected void onDetachedFromWindow()
  {
    removeView(this.l);
    removeView(this.b);
    removeView(this.m);
  }

  protected void onDraw(Canvas paramCanvas)
  {
    super.onDraw(paramCanvas);
  }

  public void onFocusChanged(boolean paramBoolean, int paramInt, Rect paramRect)
  {
    this.b.a(paramBoolean, paramInt, paramRect);
    super.onFocusChanged(paramBoolean, paramInt, paramRect);
  }

  public boolean onKeyDown(int paramInt, KeyEvent paramKeyEvent)
  {
    boolean bool;
    if (this.b.a(paramInt, paramKeyEvent))
      bool = true;
    while (true)
    {
      return bool;
      bool = super.onKeyDown(paramInt, paramKeyEvent);
    }
  }

  public boolean onKeyUp(int paramInt, KeyEvent paramKeyEvent)
  {
    boolean bool;
    if (this.b.b(paramInt, paramKeyEvent))
      bool = true;
    while (true)
    {
      return bool;
      bool = super.onKeyUp(paramInt, paramKeyEvent);
    }
  }

  protected void onLayout(boolean paramBoolean, int paramInt1, int paramInt2, int paramInt3, int paramInt4)
  {
    int i6;
    View localView;
    this.e = (paramInt3 - paramInt1);
    this.f = (paramInt4 - paramInt2);
    this.b.setLayoutParams(new ViewGroup.LayoutParams(this.e, this.f));
    this.b.setVisibility(0);
    this.b.layout(0, 0, this.e, this.f);
    this.l.setLayoutParams(new ViewGroup.LayoutParams(this.e, this.f));
    this.l.setVisibility(0);
    this.l.measure(paramInt3 - paramInt1, paramInt4 - paramInt2);
    int i1 = this.l.getMeasuredWidth();
    int i2 = this.l.getMeasuredHeight();
    this.l.layout(paramInt3 - 10 - i1, paramInt4 - 5 - i2 - paramInt2, paramInt3 - 10, paramInt4 - 5 - paramInt2);
    this.m.setLayoutParams(new ViewGroup.LayoutParams(this.e, this.f));
    this.m.setVisibility(0);
    this.m.measure(paramInt3 - paramInt1, paramInt4 - paramInt2);
    int i3 = this.m.getMeasuredWidth();
    int i4 = this.m.getMeasuredHeight();
    if (i2 > i4)
    {
      this.m.layout(10, paramInt4 - 5 - i2 - paramInt2, i3 + 10, paramInt4 - 5 - paramInt2);
      int i5 = getChildCount();
      i6 = 0;
      if (i6 >= i5)
        return;
      localView = super.getChildAt(i6);
      if ((localView != this.m) && (localView != this.l) && (localView != this.b))
        break label324;
    }
    while (true)
    {
      while (true)
      {
        while (true)
          ++i6;
        i2 = i4;
      }
      label324: a(localView, localView.getLayoutParams());
    }
  }

  protected void onMeasure(int paramInt1, int paramInt2)
  {
    super.onMeasure(paramInt1, paramInt2);
  }

  public void onRestoreInstanceState(Bundle paramBundle)
  {
    int i1 = paramBundle.getInt("lat");
    int i2 = paramBundle.getInt("lon");
    if ((i1 != 0) && (i2 != 0))
      a(new GeoPoint(i1, i2));
    int i3 = paramBundle.getInt("zoom");
    if (i3 != 0)
      a(i3);
    setTraffic(paramBundle.getBoolean("traffic"));
  }

  public void onSaveInstanceState(Bundle paramBundle)
  {
    GeoPoint localGeoPoint = getMapCenter();
    paramBundle.putInt("lat", localGeoPoint.getLatitudeE6());
    paramBundle.putInt("lon", localGeoPoint.getLongitudeE6());
    paramBundle.putInt("zoom", getZoomLevel());
    paramBundle.putBoolean("traffic", isTraffic());
  }

  protected void onSizeChanged(int paramInt1, int paramInt2, int paramInt3, int paramInt4)
  {
    super.onSizeChanged(paramInt1, paramInt2, paramInt3, paramInt4);
    this.e = paramInt1;
    this.f = paramInt2;
  }

  public boolean onTouchEvent(MotionEvent paramMotionEvent)
  {
    boolean bool;
    if (this.b.a(paramMotionEvent))
      bool = true;
    while (true)
    {
      return bool;
      bool = super.onTouchEvent(paramMotionEvent);
    }
  }

  public boolean onTrackballEvent(MotionEvent paramMotionEvent)
  {
    boolean bool;
    if (this.b.b(paramMotionEvent))
      bool = true;
    while (true)
    {
      return bool;
      bool = super.onTrackballEvent(paramMotionEvent);
    }
  }

  public void onWindowFocusChanged(boolean paramBoolean)
  {
    super.onWindowFocusChanged(paramBoolean);
  }

  public void preLoad()
  {
  }

  public void setBuiltInZoomControls(boolean paramBoolean)
  {
    if (paramBoolean)
    {
      removeView(this.l);
      addView(this.l);
    }
    while (true)
    {
      return;
      removeView(this.l);
    }
  }

  public void setDrawOverlayWhenZooming(boolean paramBoolean)
  {
    this.b.a(paramBoolean);
  }

  public void setReticleDrawMode(a parama)
  {
    throw new RuntimeException("this feature is not implemented!!");
  }

  public void setSatellite(boolean paramBoolean)
  {
    throw new RuntimeException("this feature is not implemented!!");
  }

  public void setStreetView(boolean paramBoolean)
  {
    throw new RuntimeException("this feature is not implemented!!");
  }

  public void setTraffic(boolean paramBoolean)
  {
    Bundle localBundle = new Bundle();
    localBundle.putInt("act", 1001);
    localBundle.putInt("opt", 10020400);
    if (paramBoolean)
      localBundle.putInt("on", 1);
    while (true)
    {
      Mj.sendBundle(localBundle);
      this.g = paramBoolean;
      return;
      localBundle.putInt("on", 0);
    }
  }

  public static class LayoutParams extends ViewGroup.LayoutParams
  {
    public static final int BOTTOM = 80;
    public static final int BOTTOM_CENTER = 81;
    public static final int CENTER = 17;
    public static final int CENTER_HORIZONTAL = 1;
    public static final int CENTER_VERTICAL = 16;
    public static final int LEFT = 3;
    public static final int MODE_MAP = 0;
    public static final int MODE_VIEW = 1;
    public static final int RIGHT = 5;
    public static final int TOP = 48;
    public static final int TOP_LEFT = 51;
    public int alignment;
    public int mode;
    public GeoPoint point;
    public int x;
    public int y;

    public LayoutParams(int paramInt1, int paramInt2, int paramInt3, int paramInt4, int paramInt5)
    {
      super(paramInt1, paramInt2);
      this.mode = 1;
      this.point = null;
      this.x = 0;
      this.y = 0;
      this.alignment = 51;
      this.mode = 1;
      this.x = paramInt3;
      this.y = paramInt4;
      this.alignment = paramInt5;
    }

    public LayoutParams(int paramInt1, int paramInt2, GeoPoint paramGeoPoint, int paramInt3)
    {
      this(paramInt1, paramInt2, paramGeoPoint, 0, 0, paramInt3);
    }

    public LayoutParams(int paramInt1, int paramInt2, GeoPoint paramGeoPoint, int paramInt3, int paramInt4, int paramInt5)
    {
      super(paramInt1, paramInt2);
      this.mode = 1;
      this.point = null;
      this.x = 0;
      this.y = 0;
      this.alignment = 51;
      this.mode = 0;
      this.point = paramGeoPoint;
      this.x = paramInt3;
      this.y = paramInt4;
      this.alignment = paramInt5;
    }

    public LayoutParams(Context paramContext, AttributeSet paramAttributeSet)
    {
      super(paramContext, paramAttributeSet);
      this.mode = 1;
      this.point = null;
      this.x = 0;
      this.y = 0;
      this.alignment = 51;
    }

    public LayoutParams(ViewGroup.LayoutParams paramLayoutParams)
    {
      super(paramLayoutParams);
      this.mode = 1;
      this.point = null;
      this.x = 0;
      this.y = 0;
      this.alignment = 51;
    }
  }

  static enum a
  {
    static
    {
      a[] arrayOfa = new a[3];
      arrayOfa[0] = a;
      arrayOfa[1] = b;
      arrayOfa[2] = c;
      d = arrayOfa;
    }
  }
}